home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_allocator.h.z / apr_allocator.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  211 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_ALLOCATOR_H
  56. #define APR_ALLOCATOR_H
  57.  
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61.  
  62. /**
  63.  * @file apr_allocator.h
  64.  * @brief APR memory allocation
  65.  *
  66.  */
  67. /**
  68.  * @defgroup APR_Pool_allocator Allocator
  69.  * @ingroup APR_Pool
  70.  * @{
  71.  */
  72.  
  73.  
  74. #include "apr.h"
  75. #include "apr_errno.h"
  76. #define APR_WANT_MEMFUNC
  77. #include "apr_want.h"
  78.  
  79. /** the allocator structure */
  80. typedef struct apr_allocator_t apr_allocator_t;
  81. /** the structure which holds information about the allocation */
  82. typedef struct apr_memnode_t apr_memnode_t;
  83.  
  84. struct apr_memnode_t {
  85.     apr_memnode_t *next;
  86.     apr_memnode_t **ref;
  87.     apr_uint32_t   index;
  88.     apr_uint32_t   free_index;
  89.     char          *first_avail;
  90.     char          *endp;
  91. };
  92.  
  93. #define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t))
  94.  
  95. /**
  96.  * Create a new allocator
  97.  * @param allocator The allocator we have just created.
  98.  *
  99.  */
  100. APR_DECLARE(apr_status_t) apr_allocator_create(apr_allocator_t **allocator);
  101.  
  102. /**
  103.  * Destroy an allocator
  104.  * @param allocator The allocator to be destroyed
  105.  * @remark Any memnodes not given back to the allocator prior to destroying
  106.  *         will _not_ be free()d.
  107.  */
  108. APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator);
  109.  
  110. /**
  111.  * Allocate a block of mem from the allocator
  112.  * @param allocator The allocator to allocate from
  113.  * @param size The size of the mem to allocate (excluding the
  114.  *        memnode structure)
  115.  */
  116. /*
  117.  * XXX: Move this to a private header file
  118.  */
  119. APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator,
  120.                                                  apr_size_t size);
  121.  
  122. /**
  123.  * Free a block of mem, giving it back to the allocator
  124.  * @param allocator The allocator to give the mem back to
  125.  * @param memnode The memory node to return
  126.  */
  127. /*
  128.  * XXX: Move this to a private header file
  129.  */
  130. APR_DECLARE(void) apr_allocator_free(apr_allocator_t *allocator,
  131.                                      apr_memnode_t *memnode);
  132.  
  133.  
  134. #include "apr_pools.h"
  135.  
  136. /**
  137.  * Set the owner of the allocator
  138.  * @param allocator The allocator to set the owner for
  139.  * @param pool The pool that is to own the allocator
  140.  * @remark Typically pool is the highest level pool using the allocator
  141.  */
  142. /*
  143.  * XXX: see if we can come up with something a bit better.  Currently
  144.  * you can make a pool an owner, but if the pool doesn't use the allocator
  145.  * the allocator will never be destroyed.
  146.  */
  147. APR_DECLARE(void) apr_allocator_owner_set(apr_allocator_t *allocator,
  148.                                           apr_pool_t *pool);
  149.  
  150. /** @deprecated @see apr_allocator_owner_set */
  151. APR_DECLARE(void) apr_allocator_set_owner(apr_allocator_t *allocator,
  152.                                           apr_pool_t *pool);
  153.  
  154. /**
  155.  * Get the current owner of the allocator
  156.  * @param allocator The allocator to get the owner from
  157.  */
  158. APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator);
  159.  
  160. /** @deprecated @see apr_allocator_owner_get */
  161. APR_DECLARE(apr_pool_t *) apr_allocator_get_owner(
  162.                                   apr_allocator_t *allocator);
  163.  
  164. /**
  165.  * Set the current threshold at which the allocator should start
  166.  * giving blocks back to the system.
  167.  * @param allocator The allocator the set the threshold on
  168.  * @param size The threshold.  0 == unlimited.
  169.  */
  170. APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator,
  171.                                              apr_size_t size);
  172.  
  173. /** @deprecated @see apr_allocator_max_free_set */
  174. APR_DECLARE(void) apr_allocator_set_max_free(apr_allocator_t *allocator,
  175.                                              apr_size_t size);
  176.  
  177. #include "apr_thread_mutex.h"
  178.  
  179. #if APR_HAS_THREADS
  180. /**
  181.  * Set a mutex for the allocator to use
  182.  * @param allocator The allocator to set the mutex for
  183.  * @param mutex The mutex
  184.  */
  185. APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator,
  186.                                           apr_thread_mutex_t *mutex);
  187.  
  188. /** @deprecated @see apr_allocator_mutex_set */
  189. APR_DECLARE(void) apr_allocator_set_mutex(apr_allocator_t *allocator,
  190.                                           apr_thread_mutex_t *mutex);
  191.  
  192. /**
  193.  * Get the mutex currently set for the allocator
  194.  * @param allocator The allocator
  195.  */
  196. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get(
  197.                                       apr_allocator_t *allocator);
  198.  
  199. /** @deprecated @see apr_allocator_mutex_get */
  200. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_get_mutex(
  201.                                       apr_allocator_t *allocator);
  202.  
  203. #endif /* APR_HAS_THREADS */
  204.  
  205. /** @} */
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209.  
  210. #endif /* !APR_ALLOCATOR_H */
  211.